<template>
  <section class="ad-carousel">
    <!-- 图片轮播 -->
    <article class="images-wrapper">
      <img v-for="item in texts.length" :key="item" :src="`src/assets/imgs/image${item}.png`" :class="['image', `img-${item}`, { show: item == carouselIndex }]" />
    </article>
    <!-- 文字轮播 -->
    <ad-text-silder :texts="texts" @getIndex="getIndex" />
  </section>
</template>
<script lang="ts" setup>
const carouselIndex = ref(1)
const texts = ["使用vite+vue+ts构建项目", "使用composition api语法", "不断学习中...", "ts仍需要漫长的学习过程", "vue源码仍需要漫长的学习过程"]
const getIndex = (index: number) => {
  carouselIndex.value = index
}
</script>
<style lang="scss" scoped>
.ad-carousel {
  position: absolute;
  height: 100%;
  width: 55%;
  left: 45%;
  top: 0;
  background-color: #ffe0d2;
  border-radius: 2rem;
  display: grid;
  grid-template-rows: auto 1fr;
  padding-bottom: 2rem;
  overflow: hidden;
  transition: 0.8s ease-in-out;
  .images-wrapper {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    .image {
      width: 100%;
      grid-column: 1/2;
      grid-row: 1/2;
      opacity: 0;
      transition: opacity 0.3s, transform 0.5s;
    }
    .img-1 {
      transform: translate(0, -50px);
    }
    .img-2 {
      transform: scale(0.4, 0.5);
    }

    .img-3 {
      transform: scale(0.3) rotate(-20deg);
    }
    .show {
      opacity: 1;
      transform: none;
    }
  }

  .text-slider {
    @include flex;
    justify-content: center;
    flex-direction: column;
    .text-wrap {
      max-height: 2.2rem;
      overflow: hidden;
      margin-bottom: 2.5rem;
      .text-group {
        display: flex;
        flex-direction: column;
        text-align: center;
        transform: translateY(0);
        transition: 0.5s;
        h2 {
          line-height: 2.2rem;
          font-weight: 600;
          font-size: 1.6rem;
        }
      }
    }

    .bullets {
      @include flex;
      justify-content: center;
      span {
        display: block;
        width: 0.5rem;
        height: 0.5rem;
        background-color: #aaa;
        margin: 0 0.25rem;
        border-radius: 50%;
        cursor: pointer;
        transition: 0.3s;
      }
      .active {
        width: 1.1rem;
        background-color: #151111;
        border-radius: 1rem;
      }
    }
  }
}
@media (max-width: 850px) {
  .ad-carousel {
    position: revert;
    height: auto;
    width: 100%;
    padding: 1.6rem 2rem;
    display: flex;
    .images-wrapper {
      display: none;
    }

    .text-slider {
      width: 100%;
    }
  }
}
@media (max-width: 530px) {
  .ad-carousel {
    padding: 1.5rem 1rem;
    border-radius: 1.6rem;
    .text-slider {
      .text-wrap {
        margin-bottom: 1rem;
        .text-group {
          h2 {
            font-size: 1.2rem;
          }
        }
      }
    }
  }
}
</style>
